package top.xiaoshuaila.searescue.task;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.xiaoshuaila.searescue.service.AfterWebSocket;
import top.xiaoshuaila.searescue.util.CoordinateConversion;

import java.util.HashMap;
import java.util.Random;

@Component
public class WebsocketTask {
    @Autowired
    private AfterWebSocket afterWebSocket;


    //@Scheduled(cron = "0/4 * * * * ?")
    public void websocketTask(){
        double[]point=new double[]{114.31736019981723+new Random().nextDouble()-0.5,30.464856311751138+new Random().nextDouble()-0.5};
        point= CoordinateConversion.wgs84tobd09(point[0],point[1]);
        JSONObject jsonObject=new JSONObject();
        HashMap<String,Object>map=new HashMap<>();
        map.put("x",point[0]);
        map.put("y",point[1]);
        try {
            jsonObject.put("tag","coordinate");
            jsonObject.put("coordinate",map);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        afterWebSocket.sendMessage(jsonObject.toString());
    }
}
